import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import BokeList from '../views/personInformation/bokelist.vue'
import Changeinfo from '../views/personInformation/changeinfo.vue'
import Spaceinfo from '../views/personInformation/spaceinfo.vue'
import Myinfo from '../views/personInformation/myinfo.vue'
import Changemsg from '../views/personInformation/changemsg.vue'
const routes = [
  {
    path: '/',
    name: 'HomeView',
    component: HomeView
  },
  {
    path: '/login',
    name: 'LoginView',
    component: () => import(/* webpackChunkName: "about" */ '../views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'registerView',
    component: () => import(/* webpackChunkName: "about" */ '../views/registerView.vue')
  },
  {
    path: '/car',
    name: 'carView',
    component: () => import(/* webpackChunkName: "about" */ '../views/carView.vue')
  },
  {
    path: '/order',
    name: 'orderView',
    component: () => import(/* webpackChunkName: "about" */ '../views/orderView.vue')
  },
  {
    path: '/goodsDetials',
    name: 'goodsDetials',
    component: () => import(/* webpackChunkName: "about" */ '../views/goodsDetials.vue')
  },
  {
    path: '/person',
    name: 'personView',
    component: () => import(/* webpackChunkName: "about" */ '../views/personInformation/personView.vue'),
    children: [
      {
        path: 'bokelist',
        name: 'bokeList',
        component: BokeList
      },
      {
        path: 'changeinfo',
        name: 'changeInfo',
        component: Changeinfo
      },
      {
        path: 'spaceinfo',
        name: 'spaceInfo',
        component: Spaceinfo
      },
      {
        path: 'myinfo',
        name: 'myinfo',
        component: Myinfo
      },
      {
        path: 'changemsg',
        name: 'changeMsg',
        component: Changemsg
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from) => {
  console.log(to)
  console.log(from)

  // eslint-disable-next-line eqeqeq
  if (to.path == '/car' || to.path == '/order' || to.path == '/goodsDetials') {
    const token = window.localStorage.getItem('token')
    if (!token) {
      return {
        path: '/login'
      }
    }
  }
})
export default router
